package com.evaluation;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.imageio.ImageIO;
import java.util.Iterator;

/**
 * IVT绩效考核系统启动类
 */
@SpringBootApplication
@MapperScan("com.evaluation.mapper")
public class EvaluationSystemApplication {

    public static void main(String[] args) {
        // 设置ImageIO缓存目录，避免应用关闭时StreamCloser线程出现NullPointerException
        // 使用内存缓存而不是文件缓存，避免文件流关闭问题
        System.setProperty("java.awt.headless", "true");
        
        // 添加JVM关闭钩子，确保ImageIO资源正确清理
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            try {
                // 清理ImageIO的缓存流
                // 通过遍历所有ImageWriter来触发清理
                Iterator<javax.imageio.ImageWriter> writers = ImageIO.getImageWritersByFormatName("PNG");
                while (writers.hasNext()) {
                    try {
                        javax.imageio.ImageWriter writer = writers.next();
                        if (writer != null) {
                            writer.dispose();
                        }
                    } catch (Exception e) {
                        // 忽略异常
                    }
                }
            } catch (Exception e) {
                // 忽略关闭时的异常
            }
        }, "ImageIO-Cleanup-Thread"));
        
        SpringApplication.run(EvaluationSystemApplication.class, args);
        System.out.println("IVT绩效考核系统启动成功！");
        System.out.println("前端访问地址：http://localhost:8081/evaluation/h5/index.html");
        System.out.println("后端访问地址：http://localhost:8081/evaluation/admin/index.html");
    }
}
